package com.ikkong.system.util;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2020-04-04.
 */
public class CommonUtil {
    public static int IdNOToAge(String IdNO){
        int leh = IdNO.length();
        String dates="";
        if (leh == 18) {
            //int se = Integer.valueOf(IdNO.substring(leh - 1)) % 2;
            dates = IdNO.substring(6, 10);
            SimpleDateFormat df = new SimpleDateFormat("yyyy");
            String year=df.format(new Date());
            int u=Integer.parseInt(year)-Integer.parseInt(dates);
            return u;
        }else{
            dates = IdNO.substring(6, 8);
            return Integer.parseInt(dates);
        }

    }
    public static Object fenye(List maps, int page, int rows){
        int start = (page-1)*rows;
        double d = maps.size()*1.00/rows*1.00;
        int end = start + rows;
        if (end>maps.size()){
            end = maps.size();
        }
        List<Map> newmap = maps.subList(start,end);
        Map sss = new HashMap();
        sss.put("rows",newmap);
        sss.put("total",Math.ceil(d));
        sss.put("page",page);
        sss.put("records",maps.size());
        Object o = sss;
        return o;
    }

    public static Object fenye(List maps,int page,int rows,int size){
        int start = (page-1)*rows;

        double d = size/rows;
        int end = start + rows;
        if (end>size){
            end = size;
        }
        Map sss = new HashMap();
        if(start >= size){
            sss.put("rows",new ArrayList());
        }else {
            sss.put("rows",maps);
        }

        sss.put("total",Math.ceil(d));
        sss.put("page",page);
        sss.put("records",size);


        Object o = sss;
        return o;
    }

}
